/**
 * 
 */
package server.game;

import server.exception.ServerException;

/**
 * Defines causes of end of the game.
 * 
 * @author Kamil Nowak
 *
 */
public enum EndgameCause {
	
	YOU_LOST,
	YOU_WON,
	DEADLOCK,
	YOU_LOST_TIMEOUT;
	
	/**
	 * Defines EndgameCause label - Integer mapping
	 * Integer value is used to send as a parameter to a client
	 * @param c value to map
	 * @return corresponding Integer value or 0 if mapping does not exist
	 */
	public static Integer getCode(EndgameCause c) {
		switch (c) {
			case YOU_LOST: return 1;
			case YOU_WON: return 2;
			case DEADLOCK: return 3;
			case YOU_LOST_TIMEOUT: return 4;
		}
		return 0;
	}
	
	/**
	 * Defines Integer - EndgameCause label mapping
	 * @param c value to map
	 * @return corresponding value
	 * @throws ServerException mapping does not exist
	 */
	public static EndgameCause getCause(int c) throws ServerException {
		switch (c) {
			case 1: return YOU_LOST;
			case 2: return YOU_WON;
			case 3: return DEADLOCK;
			case 4: return YOU_LOST_TIMEOUT;
			default: throw new ServerException(26);
		}
		
	}
}
